<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Administrator
 */
class InventoryList extends WMS_Controller
{

    var $whsCode;

    function __construct()
    {
        parent::__construct();
        $gp = gp();
        $userData = $this->session->userdata('users');
        $this->whsCode = $userData['user_main_whs_code'];
        //加载模型
        $this->load->service('/wms/inventory_service');
        $this->load->service('/wms/time_service');
        $this->load->service('/wms/warehouse_list_service');
        $this->load->model('/wms/api/get_product_info_from_erp');
    }

    public function get_inventory_list()
    {
        //锁死仓库
        $gp = gp();
        $whs = $gp['whs'] ? $gp['whs'] : $this->whsCode;
        $sku = $gp['sku'] ? $gp['sku'] : '';
        $page = $gp['page'] ? intval($gp['page']) : 1;
        $data['whs'] = $this->warehouse_list_service->fields_whs_array($this->whsCode);
        $str='';
        if(''!=$sku){
        $str .= 'sku=' . $sku;
        }
        if(''!=$whs&&!is_array($whs)){
        $str .= '&whs=' . $whs;
        }
        //分页查询
        $this->load->library('pagination');
        $config['page_query_string'] = TRUE;
        $config['base_url'] = blang_url('wms/InventoryList/get_inventory_list?' . $str);
        $config['total_rows'] = $this->inventory_service->get_inventory_list_total($whs, $sku);
        $config['uri_segment'] = config_item('enable_lang') ? 5 : 4;
        $config['per_page'] = 20;
        $this->pagination->initialize($config);
        $data['pageShow'] = $this->pagination->create_links();
        //分页结束
        //获取产品库存列表
        $inventoryList = $this->inventory_service->get_inventory_list($whs, $sku, $config['per_page'], ($page - 1) * $config['per_page']);
        $inventoryList = $this->get_product_info_from_erp->fields_product_info($inventoryList);
        $inventoryList = $this->time_service->show_time($inventoryList, "last_stock_time");
        $inventoryList= $this->warehouse_list_service->fields_whs_code($inventoryList);
        //构建前端数据
        $data['inventoryList'] = $inventoryList;
        $this->load->view('defaults/wms/inventory_list', $data);
        $this->load->view('defaults/common/footer', $data);
    }

    function print_sku()
    {
        $gp = gp();
        $data['whsCode'] = $this->whsCode;
        $this->load->view('defaults/wms/print_sku_panel', $data);
        $this->load->view('defaults/common/footer', $data);
    }

}

?>
